<?php
/** u2t3_SysMountPoint class
 *
 * Creates a SysMountpoint
 */

require_once(t3lib_extMgm::extPath('univis2typo3').'/mod1/configuration/include/common.php');

class u2t3_SysMountPoint {
	var $folderEscaped_ = '';
	var $nameEscaped_ = '';
	var $personKey_ = '';
	var $uid = -1;

	function u2t3_SysMountPoint() {
		// empty
	}

	function setFolder($f) {
		$this->folderEscaped_ = replaceUmlaute($f);
	}

	function setName($n) {
		$this->nameEscaped_ = replaceUmlaute($n);
	}

	function setPersonKey($k) {
		$this->personKey_ = $k;
	}

	function create() {
		if (!$this->folderEscaped_ || !$this->nameEscaped_) {
			echo "\t error: folder or name not specified<br />\n";
			return -1;
		}
		echo "\t Updating table [sys_filemounts]...<br />\n";

		$relPath = $this->folderEscaped_;
		$absPath = PATH_site.'fileadmin/'.$relPath;

		ensureFolderExists($absPath);

		$now = time();
		$hidden = 0;
		$query = "INSERT INTO `sys_filemounts`
			(`uid`, `pid`, `tstamp`, `title`, `path`, `base`, `hidden`, `deleted`, `tx_lme_person_key`) 
			VALUES
			('', 0, '{$now}', '{$this->nameEscaped_}', '".$relPath."', 1, {$hidden}, 0, '{$this->personKey_}')";
		performSQLQuery($query, false);

		echo "\t new file mount added...<br />\n";
		$this->uid = mysql_insert_id();
		return $this->uid;
	}
}
?>
